package com.surveypark.domain;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Date;

public abstract class BaseEntity implements Serializable{

	private static final long serialVersionUID = 2340663731753505862L;

	public abstract Integer getId();
	
	public abstract void setId(Integer id);
	
	@SuppressWarnings("rawtypes")
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		String className = this.getClass().getSimpleName();
		buffer.append(className + "{");
		Field[] fs = this.getClass().getDeclaredFields();
		
		try {
			Class ftype = null;
			Object fvalue = null;
			for(Field f:fs){
				ftype = f.getType();
				//基本类型/简单类型/基本类型的包装类
				if(!Modifier.isStatic(f.getModifiers()) 
						&& ftype.isPrimitive() 
						|| ftype == String.class
						|| ftype == Integer.class
						|| ftype == Long.class
						|| ftype == Date.class){//排除静态字段
					f.setAccessible(true);
					fvalue = f.get(this);//返回字段所代表的值
					buffer.append(f.getName() + ":" + fvalue + ",");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		buffer.append("}");
		return buffer.toString();
	}
}
